<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="referrer" content="no-referrer" />
    <title>可视域分析</title>
    <style>
        body {
            position: absolute;
            margin: 0;
            width: 100%;
            height: 100%;
        }

        #mapContainer {
            left: 0px;
            top: 0px;
            width: 100%;
            height: 100%;
            float: left;
        }
    </style>
</head>

<body>
    <div id="mapContainer" style="position: relative;"></div>
</body>
<script src='/GiswayEngine.js'></script>
<script type="text/javascript">
    window.app = new GE.App('mapContainer', {
        position: [120.13930316066936, 30.271773900623586, 1200], //相机的位置
        lookAt: [120.13930316066936, 30.271773900623586, 0], //相机看向的地图位置
        // position: [120.14722331340128, 30.27129365792725, 1000], //相机的位置
        // lookAt: [120.14722331340128, 30.27129365792725, 0], //相机看向的地图位置
        cameraScrollSpeed: 5, //鼠标滚动时，控制相机移动的速度
        minZoom: 3, //允许地图的最小层级
        maxZoom: 20, //允许地图的最大层级
        ambientLightIntensity: 5,
        isOpenViewFrustum: true,  //开启可视域检测的功能
        useDefaultTexture: true, //是否使用瓦片默认纹理
        background: "Fog", //背景的类型，参数有如下类型：None, Fog, Color, Gradient, Image, Sky, Image。使用Fog地图的性能会比较好
        // backGroundColorA:'#AAAAFF', //当background的值为Gradient时，需要配置该参数。最下端颜色，默认值为#0000FF
        // backGroundColorB:'#0000FF', //当background的值为Gradient时，需要配置该参数。最上端颜色，默认值为#FF0000
        // backGroundColor: '#F5F5F5', //当background的值为Color时，需要配置该参数，默认值为#00BFFF
        // imageUrl: 'http://localhost:9000/examples/assets/img_logo.39362dc1.png', //当background的值为Image时，需要配置该参数。默认值为null
        baseLayer: [
            //影像底图
            {
                url: ' https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', //影像底图的url
                // url: 'http://115.236.87.26:8848/googleTiles/china_image/{z}/{y}/{x}.jpg',
                urlDecimal: true, //影像底图url中的瓦片行列号是否是十进制，true表示十进制，false表示十六进制
                tileType: 'image', //影像底图
                canNotSelect: false, //true表示该图层不参与射线拾取，false表示图层参与射线拾取
            },
            //shape底图
            {
                url: 'http://localhost:9009/examples/resources/shape/Tiles/L{z}/{y}/{x}.shp',
                // url: 'http://localhost:9000/examples/resources/shp/Tiles/L{z}/{y}/{x}.shp', //shape底图的url
                urlDecimal: true, //shape底图url中的瓦片行列号是否是十进制，true表示十进制，false表示十六进制
                tileType: 'shape',  //shape底图
                canNotSelect: true, //true表示该图层不参与射线拾取，false表示图层参与射线拾取
                merge: true //几何体是否合并
            }
        ]
    });





    window.app.on('Click', function (e) {
        console.log(e);
        let curObj = e.object;
        while (curObj) {
            if (curObj instanceof GE.OverLay) {
                if (curObj.options.type == 'fbx') {
                    console.log('this is a fbx');
                    return;
                }
            }
            curObj = curObj.parent;
        }
    });
    var viewFieldAnalysis;

    btn();
    function btn() {
        let button1 = new GE.Button('打开可视域分析', function () {
            if (viewFieldAnalysis) {
                return;
            }
            openAnalysis();
        });
        app.ui.add(button1);

        let button2 = new GE.Button('旋转可视域分析', function () {
            if (!viewFieldAnalysis) {
                return;
            }
            viewFieldAnalysis.setControlModel('rotate');
        });
        app.ui.add(button2);

        let button3 = new GE.Button('平移可视域分析', function () {
            if (!viewFieldAnalysis) {
                return;
            }
            viewFieldAnalysis.setControlModel('translate');
        });
        app.ui.add(button3);

        let button4 = new GE.Button('隐藏控制器', function () {
            if (!viewFieldAnalysis) {
                return;
            }
            viewFieldAnalysis.hideControl();
        });
        app.ui.add(button4);

        let button5 = new GE.Button('关闭可视域分析', function () {
            closeAnalysis();
            viewFieldAnalysis = null;
        });
        app.ui.add(button5);
    }

    function openAnalysis() {
        if (!viewFieldAnalysis) {
            let aspect = 1.2722371967654986;
            let cameraParam = {
                cameraPosition: new GE.Point(120.13930316066936, 30.271773900623586, 100, '4326'),
                targetPosition: new GE.Point(120.13930316066936, 30.275773900623586, 0, '4326'),
                fov: 40,
                aspect: aspect,
                near: 200,
                far: 1000,
            }
            let viewFieldColor = '#7FFF00'; //可视域内的颜色
            viewFieldAnalysis = new GE.ViewFieldAnalysis(viewFieldColor);
            viewFieldAnalysis.openAnalysis(cameraParam);
            viewFieldAnalysis.setCoverShadow({isCoverShadow: true, shadowColor: '#DC143C'})
        }
    }

    function closeAnalysis() {
        if (!viewFieldAnalysis) {
            return;
        }
        viewFieldAnalysis.closeAnalysis();
    }

    var model;
    function fbx() {
        model = new GE.OverLay({
            type: 'fbx',
            url: 'http://localhost:9000/examples/resources/fbx/xqazm.fbx',
            position: [120.13930316066936, 30.271773900623586, 50],
            // scale: [100, 100, 100],
            // rotation: [45, 0, 0],
            success: function () {
                // setTimeout(btn, 300);
                // btn();
            }
        });
        app.add(model);
    }

    fbx();

</script>

</html>